package com.xiaozhou.leetCode.leetCode100;

public class LeetCode7 {

    public static int reverse(int x) {
        if (x == 0){
            return 0;
        }
        if (x > 0){
            return reversePositive(x);
        }else {
            return reversePositive(-x) * -1;
        }
    }
    public static int reversePositive(int x){
        long reverse = 0;
        while (x != 0){
            int pop = x % 10;
            reverse = pop + reverse * 10;
            x /= 10;
        }
        if (reverse > Integer.MAX_VALUE){
            return 0;
        }
        return (int) reverse;
    }

    public static void main(String[] args) {
        int reverse = reverse(1534236469);
        System.out.println(reverse);
    }
}
